﻿/**************************** DEPRECATED FUNCTIONS *****************************************/
/* Get the number of moves. */
function getMoves()
{
	if ( wave.getState() )
	{
		return parseInt( wave.getState().get( "moves", "0" ) );
	}
	else
	{
		return 0;
	}
}



//this function will reset the form and then run the totomat
function totomat(){
	answer=confirm("filling the form automatically will delete all current filled out squares. are you sure you want to proceed?");
	if (answer !=0){ 
		doReset(1);
		setTimeout('runTotomat()',500);
	}
}

//this function will do the actual randomization
function runTotomat(){
	var game = gameState();
	var new_account=accountState();
	var temp;
	for (i=0;i<16;i++){
		temp=Math.floor(Math.random()*3);
		game[i][temp]=!game[i][temp];
	}

	//for debugging
	/*for (i=0;i<16;i++){
					for (j=0;j<3;j++){
					alert(game[i,j]);
					}
				}*/


	var cost=new Number();
	var numOfCols= getCols(game)[16];
	cost=(numOfCols*2.8).toFixed(2);
	wave.getState().submitDelta( { "game"  : wave.util.printJson( game ),
		"cost" : cost});

	//setTimeout('runTotomatTest()',2000);
}

function fillingAccount(Participants,account){
	var howManyTotla_t="";
	for ( par = 0; par < Participants.length; par++ ){
		var name=Participants[par].getDisplayName();
		var id=Participants[par].getId();	
		var count=0;
		forEachCell(function(row,col){if (account[row][col]==id) count++;});
		var square_t=count==1?" square":" squares";
		var howMany_t=name+" filled "+count+square_t;
		var howManyTotla_t=howManyTotla_t+"\n"+howMany_t+". ";
	}
	return howManyTotla_t;
}

/* Update the display of number of moves. */
function refreshMoves( gameState )
{
	var moves   = getMoves();
	var moves_t = moves == 1 ? "move" : "moves";
	var counter= isDone(gameState);
	var counter_t= counter==1?" game ":" games ";

	document.getElementById( "moves" ).innerHTML =
		"After " + moves + " " + moves_t + " You still have "+ counter+counter_t+ "left to fill.";
	document.getElementById( "Who" ).innerHTML = fillingAccount(wave.getParticipants(),accountState());

}

function resetGame()
{	
	answer = confirm("Do you really want to Reset");
	doReset(answer);

}
function testOldFormList(){
		
		var date;
		var oldForms= getOldFormsListFromState();
		for (i=0;i<oldForms.length;i++){
		date=new Date(parseInt(oldForms[i]))
		alert(oldForms[i]);
		alert(date);
		alert(date.toLocaleDateString());
		}
	}


/*this is a function for debugging of the checkResults function
		function testMyResults(){
		var id=wave.getState().get("idiotID");
		alert("callback"+correctResultsDisplayState()[0][0]);
		alert("callback"+correctResultsDisplayState()[0][1]);
		alert("callback"+correctResultsDisplayState()[0][2]);
		if (id==-1) alert("no idiot");
		else alert("callback:"+"idiot:"+wave.getParticipantById(wave.getState().get("idiotID")).getDisplayName());
		alert("callback:"+"guesses:"+wave.getState().get("numberOfCorrectGuesses"));
		alert("callback:"+"prize:"+wave.getState().get("prize"));
		}*/


/*function testMyLastWeek(){
		var id=wave.getState().get("lw_idiotID");
		alert("lastWeek"+lw_correctResultsDisplayState()[0][0]);
		alert("lastWeek"+lw_correctResultsDisplayState()[0][1]);
		alert("lastWeek"+lw_correctResultsDisplayState()[0][2]);
		if (id==-1) alert("lastWeek- no idiot");
		else alert("lastWeek:"+"idiot:"+wave.getParticipantById(wave.getState().get("lw_idiotID")).getDisplayName());
		alert("lastWeek:"+"guesses:"+wave.getState().get("lw_numberOfCorrectGuesses"));
		alert("lastWeek:"+"cost:"+wave.getState().get("lw_cost"));
		alert("lastWeek:"+"prize:"+wave.getState().get("lw_prize"));
		}*/


/************ DEPRACATED FUNCTION
function RefreshRec(){
	if(parseInt(wave.getState().get("RecommendationsReq"))){ //if a request for recommendations was made
		TextRecArr = Recommendations(1);
		FinalRecArr = Recommendations(0);
		if(TextRecArr && FinalRecArr){
			var TempCell;
			for(i=0;i<16;i++){
				TempCell = document.getElementById( "tip" + i);
				TempCell.title = TextRecArr[15-i] + " " + FinalRecArr[15-i];
			}
		}
	}
	else{//clear the recommendations
		for(i=0;i<16;i++){
			TempCell = document.getElementById( "tip" + i);
			TempCell.title = "";
		}
	}
}****************************************************/


/******** NEW FUNTIONS **********************************/


		


	


